package com.hfi.command.demo03;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2020/4/26
 */
public class Waiter {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    //服务员

    private List<Command> orders = new ArrayList<>();

    //设置订单
    public void setOrder(Command command) {
        if (StringUtils.equals(command.toString(), "烤鸡翅")) {
            logger.info("服务员：鸡翅没有了，请点别的烧烤。");
        } else {
            orders.add(command);
            logger.info("增加订单：" + command.toString() + "  时间：" + LocalTime.now().toString());
        }
    }

    public void cancelOrder(Command command) {
        if (command.cancelCommand().isSuccess()) {
            orders.remove(command);
        }
        logger.info(command.cancelCommand().getMsg() + "  时间：" + LocalTime.now().toString());
    }

    //通知执行
    public void notifyExecute() {
        orders.forEach(Command::executeCommand);
    }
}
